package com.med.controller;

import com.med.dto.RespondDTO;
import com.med.service.IMineService;
import com.med.util.IdentificationOCRUtil;
import com.med.util.SendCodeUtil;
import com.med.util.ValidateCodeUtil;
import com.med.vo.CommentsVO;
import com.med.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * @BelongsProject: internet-based-healthcare
 * @BelongsPackage: com.med.controller
 * @Author: 小吴
 * @CreateTime: 2025-08-26 14:47
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/mine")
@RefreshScope
public class MineController {
    @Autowired
    private IMineService mineService;

    @Autowired
    private SendCodeUtil sendCodeUtil; //短信验证码

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    /**
     * @Description: 根据id查询个人信息
     * @Param:
     * @return:
     */
    @RequestMapping("/queryUser")
    public RespondDTO queryUser(UserVO userVO) {
        RespondDTO queryUser = mineService.queryUser(userVO);
        return queryUser;
    }

    /**
     * @Description: 个人中心修改
     * @Param:
     * @return:
     */
    @RequestMapping("/updateUser")
    public RespondDTO updateUser(UserVO userVO) {
        System.err.println(userVO);
        RespondDTO updateUser = mineService.updateUser(userVO);
        return updateUser;
    }

    /**
     * @Description: 个人中心修改-发送验证码
     * @Param:
     * @return:
     */
    @PostMapping("/sendCode")
    public RespondDTO sendCode(@RequestBody UserVO userVO) {
        String phone = userVO.getPhone();
        //生成验证码
        String code = ValidateCodeUtil.generateCode();
        sendCodeUtil.sendVerificationCode(phone, code);
        //验证码存redis
        redisTemplate.opsForValue().set("mineCode", code, 5, TimeUnit.MINUTES);
        return RespondDTO.success();
    }

    /**
     * @Description: 我的评论--根据用户id来查询对医生的评论
     * @Param:
     * @return:
     */
    @RequestMapping("/queryComments")
    public RespondDTO queryComments(CommentsVO commentsVO) {
        System.err.println(commentsVO);
        RespondDTO queryComments = mineService.queryComments(commentsVO);
        return queryComments;
    }

    @RequestMapping("/deleteComment")
    public RespondDTO updateComment(CommentsVO commentsVO) {
        RespondDTO updateComments = mineService.updateComments(commentsVO);
        return updateComments;
    }
}
